package org.zk.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.zk.entity.User;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RequestMapping("/fm")
@Controller
public class FmController {

    @RequestMapping("/toUser")
    public ModelAndView toUser() {
        User user = new User();
//        user.setUserName("林教头");
        user.setBirthday(new Date());
        ModelAndView mv = new ModelAndView();
        mv.addObject("user", user);
        mv.setViewName("user");
        return mv;
    }

    @RequestMapping("/getUsers")
    public ModelAndView getUsers(HttpSession session) {
        ModelAndView mv = new ModelAndView();
        User user1 = new User();
        user1.setUserName("林教头");
        User user2 = new User();
        user2.setUserName("陆迁");
        User user3 = new User();
        user3.setUserName("高衙内");

        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);

        mv.addObject("userss", list);
        session.setAttribute("user", user1);
        mv.setViewName("user");
        return mv;

    }


}
